home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / lego.pro < prev    next >
Text File  |  1997-07-08  |  10KB  |  296 lines

  1. ; $Id: lego.pro,v 1.3 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ;+
  7. ; NAME:    
  8. ;    LEGO
  9. ;
  10. ; PURPOSE:
  11. ;    This procedure plots a lego graph of 2-dimensional data. 
  12. ;
  13. ; CATEGORY:
  14. ;    Plotting.
  15. ;
  16. ; CALLING SEQUENCE:
  17. ;    LEGO, Data, Xa, Ya
  18. ;
  19. ; INPUTS:
  20. ;    Data:      A 2-dimensional array.
  21. ;    Xa:      If present, a 1-dimensional array of X coordinates.
  22. ;        Ya:      If present, a 1-dimensional array of Y coordinates.
  23. ;
  24. ; KEYWORD PARAMETERS:
  25. ;     BARSPACE: If this keyword is specified, LEGO will leave space
  26. ;          between the bars. The value of BARSPACE must be
  27. ;          between 0.0 and 0.8.
  28. ;    OUTLINE:  If this keyword is specified, LEGO will draw ONLY the
  29. ;              outline of the bars. This is useful when creating black
  30. ;          and white hardcopy.
  31. ;    SHADES:   If this keyword is specified, LEGO will draw ONLY the
  32. ;              shaded part of the bars.
  33. ;    DELTA:    This keyword allows fine adjustment of the width
  34. ;          of the bar outlines. RECOMMENDED USE: lower delta value
  35. ;          for a small data set and higher delta value for a
  36. ;          large data set. The value of DELTA must be between
  37. ;          0.07 and 0.15
  38. ;       The following keywords to SURFACE are also applicable:
  39. ;          AX, AZ, CHARSIZE, CHARTHICK, FONT, XMARGIN, YMARGIN,
  40. ;          SUBTITLE, TICKLEN, TITLE, (XYZ)CHARSIZE, (XYZ)MINOR,
  41. ;          (XYZ)RANGE, (XYZ)STYLE, (XYZ)TICKNAME, (XYZ)TICKS,
  42. ;          (XYZ)TICKV, (XYZ)TITLE, BACKGROUND
  43. ;
  44. ; OUTPUTS:
  45. ;    The LEGO procedure creates a lego graph on the currently selected
  46. ;    device.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    A graphics window is created if none currently exist.
  50. ;
  51. ; RESTRICTIONS:
  52. ;       This procedure does not work with the HP device. Of Tektronix
  53. ;    terminals, only the 4100 series is supported.
  54. ;
  55. ; PROCEDURE:
  56. ;    Straightforward.
  57. ;
  58. ; EXAMPLE:
  59. ;    X = FINDGEN(10, 10)    ; create 2D array to plot
  60. ;    LEGO, X            ; create plot
  61. ;
  62. ; MODIFICATION HISTORY:
  63. ;       12/20/91 - Initial creation - jiy (RSI)
  64. ;    06/15/92 - Modified to produce better PS output - jiy (RSI)
  65. ;       08/28/92 - modified to better deal with small arrays -jiy (RSI)
  66. ;-
  67.  
  68. PRO lego,data,xa,ya,ax=ax,az=az,charsize=charsize,charthick=charthick,$
  69.               font=font,xmargin=xmargin,ymargin=ymargin,subtitle=subtitle,$
  70.               ticklen=ticklen,title=title,xcharsize=xcharsize,$
  71.               ycharsize=ycharsize,zcharsize=zcharsize,$
  72.               xminor=xminor,yminor=yminor,zminor=zminor,$
  73.               xrange=xrange,yrange=yrange,zrange=zrange,$
  74.               xstyle=xstyle,ystyle=ystyle,zstyle=zstyle,$
  75.               xtickname=xtickname,ytickname=ytickname,ztickname=ztickname,$
  76.               xticks=xticks,yticks=yticks,zticks=zticks,$
  77.               xtickv=xtickv,ytickv=ytickv,ztickv=ztickv,$
  78.               xtitle=xtitle,ytitle=ytitle,ztitle=ztitle,$
  79.               background=background,color=color,barspace=barspace, $
  80.               outline=outline,shades=shades,delta=delta
  81.  
  82.    ; get the type of the data passed in
  83.    form = size(data);
  84.    sizx = size(xa);
  85.    sizy = size(ya);
  86.  
  87.    if (form(0) ne 2) then begin
  88.       message,'Array must have 2 dimensions',/traceback
  89.       return;
  90.    endif;
  91.  
  92.    if (sizx(0) ne 0) then begin
  93.       if (sizx(0) ne 1) then begin
  94.          print,'X array must have 1 Dimension -> Using default';
  95.          sizx(0) = 0;
  96.       endif;
  97.       if (sizx(1) ne form(1)) then begin
  98.          print,'X array dimension incompatible with Z array - Using Default';
  99.          sizx(0) = 0;
  100.       endif;
  101.    endif;
  102.  
  103.    if (sizy(0) ne 0) then begin
  104.       if (sizy(0) ne 1) then begin
  105.          print,'Y array must have 1 Dimension -> Using default';
  106.          sizy(0) = 0;
  107.       endif;
  108.       if (sizy(1) ne form(2)) then begin
  109.          print,'Y array dimension incompatible with Z array - Using Default';
  110.          sizy(0) = 0;
  111.       endif;
  112.    endif;
  113.  
  114.    ; setting default
  115.    if (sizx(0) eq 0) then xa = indgen (form(1));
  116.    if (sizy(0) eq 0) then ya = indgen (form(2));
  117.  
  118.    if (n_elements(ax) eq 0) then ax=30;
  119.    if (n_elements(az) eq 0) then az=30;
  120.  
  121.    if (n_elements(charsize)  eq 0) then charsize =1;
  122.    if (n_elements(charthick) eq 0) then charthick=1;
  123.    if (n_elements(font)      eq 0) then font     =0;
  124.  
  125.    if (n_elements(xmargin) eq 0) then xmargin = [10,3];
  126.    if (n_elements(ymargin) eq 0) then ymargin = [ 4,2];
  127.  
  128.    if (n_elements(subtitle) eq 0) then subtitle = '';
  129.    if (n_elements(title)    eq 0) then title    = '';
  130.    if (n_elements(ticklen)  eq 0) then ticklen  = 0.02;
  131.  
  132.    if (n_elements(xcharsize) eq 0) then xcharsize = 1;
  133.    if (n_elements(ycharsize) eq 0) then ycharsize = 1;
  134.    if (n_elements(zcharsize) eq 0) then zcharsize = 1;
  135.  
  136.    if (n_elements(xminor) eq 0) then xminor = 0;
  137.    if (n_elements(yminor) eq 0) then yminor = 0;
  138.    if (n_elements(zminor) eq 0) then zminor = 0;
  139.  
  140.    if (n_elements(xstyle) eq 0) then xstyle = 0;
  141.    if (n_elements(ystyle) eq 0) then ystyle = 0;
  142.    if (n_elements(zstyle) eq 0) then zstyle = 0;
  143.  
  144.    if (n_elements(xtickname) eq 0) then xtickname = [''];
  145.    if (n_elements(ytickname) eq 0) then ytickname = [''];
  146.    if (n_elements(ztickname) eq 0) then ztickname = [''];
  147.  
  148.    if (n_elements(xticks) eq 0) then xticks=0;
  149.    if (n_elements(yticks) eq 0) then yticks=0;
  150.    if (n_elements(zticks) eq 0) then zticks=0;
  151.  
  152.    if (n_elements(xtickv) eq 0) then xtickv = [''];
  153.    if (n_elements(ytickv) eq 0) then ytickv = [''];
  154.    if (n_elements(ztickv) eq 0) then ztickv = [''];
  155.  
  156.    if (n_elements(xtitle) eq 0) then xtitle = '';
  157.    if (n_elements(ytitle) eq 0) then ytitle = '';
  158.    if (n_elements(ztitle) eq 0) then ztitle = '';
  159.  
  160.    if (n_elements(xrange) eq 0) then xrange = [min(xa),max(xa)+1];
  161.    if (n_elements(yrange) eq 0) then yrange = [min(ya),max(ya)+1];
  162.    if (n_elements(zrange) eq 0) then zrange = [min(data),max(data)];
  163.  
  164.    if (n_elements(background) eq 0) then background = !p.background;
  165.    if (n_elements(color)      eq 0) then color      = !p.color;
  166.    if (n_elements(barspace)   eq 0) then barspace   = 0.0;
  167.    if (barspace gt 0.8)             then barspace   = 0.0;
  168.  
  169.    if (n_elements(shades)     eq 0) then draw       = 1 else draw = 0;
  170.  
  171.    dev_name = !D.NAME;   get the name of the current device
  172.  
  173.    ; define polygons - one face at a time & counterclock-wise
  174.    polys  = [4,0,1,2,3, 4,4,5,6,7, 4,0,1,5,4,$
  175.          4,1,2,6,5, 4,2,3,7,6, 4,3,0,4,7];
  176.    poly   = [0,1,2,3,0, 4,5,6,7,4, 0,1,5,4,0,$
  177.          1,2,6,5,1, 2,3,7,6,2, 3,0,4,7,3];
  178.  
  179.    if (n_elements(outline)    eq 0) then $
  180.       shades = [0.8,0.8,1.0,0.7,1.0,0.7] * (!d.n_colors-1) $
  181.    else $
  182.       shades = [0,0,0,0,0,0];
  183.  
  184.    ; calculate the equivalent size in z-buffer
  185.    zsize = lonarr (2)
  186.    
  187.    if (!d.name eq 'PS') then begin
  188.       zsize(0) = 640.0 * !d.x_size / 17780.0;
  189.       zsize(1) = 512.0 * !d.y_size / 12700.0;
  190.    endif else if (!d.name eq 'TEK') then begin
  191.       zsize(0) = 640.0 * !d.x_size / 4096.0;
  192.       zsize(1) = 512.0 * !d.y_size / 3129.0;
  193.    endif else if (!d.name eq 'PCL') then begin
  194.       zsize(0) = 640.0 * !d.x_size / 2100.0;
  195.       zsize(1) = 512.0 * !d.y_size / 1500.0;
  196.    endif else if (!d.name eq 'CGM') then begin
  197.       zsize(0) = 512.0 * !d.x_size / 32768.0;
  198.       zsize(1) = 512.0 * !d.y_size / 32768.0;
  199.    endif else begin
  200.       zsize(0) = !d.x_size;
  201.       zsize(1) = !d.y_size;
  202.    endelse;
  203.  
  204.    set_plot,'z';
  205.    device,set_res = zsize;
  206.    erase; 
  207.  
  208.    surface,data,xa,ya,/nodata,/save, ax=ax, az=az, charsize=charsize, $
  209.            charthick = charthick, font=font, $
  210.            xmargin=xmargin,ymargin=ymargin,subtitle=subtitle,$
  211.            ticklen=ticklen,title=title,xcharsize=xcharsize,$
  212.            ycharsize=ycharsize,zcharsize=zcharsize,$
  213.            xminor=xminor,yminor=yminor,zminor=zminor,$
  214.            xrange=xrange,yrange=yrange,zrange=zrange,$
  215.            xstyle=xstyle,ystyle=ystyle,zstyle=zstyle,$
  216.            xtickname=xtickname,ytickname=ytickname,ztickname=ztickname,$
  217.            xticks=xticks,yticks=yticks,zticks=zticks,$
  218.            xtickv=xtickv,ytickv=ytickv,ztickv=ztickv,$
  219.            xtitle=xtitle,ytitle=ytitle,ztitle=ztitle,$
  220.            background=background
  221.  
  222.    set_shading,/gouraud;
  223.  
  224.    if (barspace) then begin
  225.       add = barspace/2.0;
  226.       del = 1.0 - add;
  227.    endif else begin
  228.       add = 0;
  229.       del = 1;
  230.    endelse;
  231.  
  232.    if (n_elements(delta) eq 0) then $
  233.       delta = sqrt(form(1)*form(2))/500. $
  234.    else delta = delta;
  235.  
  236.    if (delta lt .015) then delta = .015;
  237.    if (delta gt .07) then delta = .07;
  238.    
  239.    add1 = add+delta;
  240.    del1 = del-delta;
  241.    maxi = max (data);
  242.  
  243.    zmin = min (data);
  244.  
  245.    for i=0,form(1)-1 do begin
  246.       for j=0,form(2)-1 do begin
  247.          x = xa(i);
  248.          y = ya(j);
  249.          z = data(i,j);
  250.      if z eq zmin then begin
  251.             kin = 0 & kfin = 0;
  252.          endif else begin
  253.             kin = 0 & kfin = 5;
  254.          endelse;
  255.  
  256.          v = [ [x+add,y+add,zmin ],  [x+del,y+add, zmin ],    $
  257.            [x+del,y+del, zmin ], [x+add,y+del,zmin ],    $
  258.            [x+add,y+add,z ],  [x+del,y+add,z ],    $
  259.            [x+del,y+del,z ], [x+add,y+del,z ] ];
  260.      z=z-delta;
  261.          vs = [ [x+add1,y+add1,zmin ],  [x+del1,y+add1, zmin ],    $
  262.            [x+del1,y+del1, zmin ], [x+add1,y+del1,zmin ],    $
  263.            [x+add1,y+add1,z ],  [x+del1,y+add1,z ],$
  264.            [x+del1,y+del1,z ], [x+add1,y+del1,z ] ];
  265.  
  266.          if (draw) then begin
  267.         if (kin eq kfin) then begin
  268.                plots,v(*,poly(kin*5:kin*5+4)),/t3d,thick=1.8,/data;
  269.         endif else begin           
  270.                for k=kin,kfin do begin
  271.                   col = shades(k) * (z/maxi);
  272.                   polyfill,vs(*,polys(k*5+1:k*5+4)),/t3d,color = col,/data;
  273.                   plots,v(*,poly(k*5:k*5+4)),/t3d,thick=1.8,/data;
  274.                endfor;
  275.             endelse;
  276.          endif else begin
  277.             a = polyshade(v,polys,/t3d);
  278.          endelse;
  279.  
  280.       endfor;
  281.    endfor;
  282.  
  283.    a = tvrd ();
  284.    set_plot,dev_name;
  285.  
  286.    ; reverse byte array for postscript output
  287.    if (dev_name eq 'PS') then begin
  288.       a = 255 - a;
  289.    endif;
  290.  
  291.    tv,a;
  292.  
  293. end;
  294.  
  295.  
  296.